<?php

class navi_top extends Load_use {
    
        private $__base_url = HOST_NAME;


    function getBlock() {
        global $navi, $count_products;
        $i = 1;
        $html = '';
        $countCats = count($navi['category']['n']);

        foreach ($navi['category']['n'] as $main_cat) {
            $html_list = '';
            if (isset($navi['sub_category']['#' . $main_cat->id . '#'])) {
                foreach ($navi['sub_category']['#' . $main_cat->id . '#'] as $cat) {
                    $count = isset($count_products[$cat->parents . '#' . $cat->id . '#']) ? $count_products[$cat->parents . '#' . $cat->id . '#'] : 0;
                    $html_list .= $count ? '<li><a href="' . $this->__base_url . '/' . $main_cat->url . '/' . $cat->url . '">' . $cat->title . '</a></li>' : '';
                }
            }
            $html .= '	<li class="main-navi__item' . ( ( $i++ == $countCats ) ? ' last-child' : '' ) . '">
							<a href="/' . $main_cat->url . '" class="main-navi__item__link">
								<span>' . implode('<br />', explode(' ', $main_cat->title, 2)) . '</span>
							</a>
							<div class="main-navi__sublist">
								<ul class="main-navi__sublist__inner">
									' . $html_list . '
								</ul>
							</div>	
						</li>';
        }

//        $a = 'Услуги';
//        $html .= '	<li class="main-navi__item  last-child">
//							<a href="/  " class="main-navi__item__link">
//								<span>' . $a . '</span>
//							</a>
//							<div class="main-navi__sublist">
//								<ul class="main-navi__sublist__inner">
//									' . $a . '
//								</ul>
//							</div>	
//						</li>';
        return '<ul class="main-navi centering">' . $html . '</ul>';
    }

}
